$(function () {
    const token = window.sessionStorage.getItem('token')
    const id = window.sessionStorage.getItem('id')
    const user_id = window.sessionStorage.getItem('user_id')
    testLogin()
    async function testLogin() {
        // console.log(token,'||||',id,user_id);
        const res = await $.ajax({
            url: 'http://localhost:8080/person/info/' + user_id,
            method: 'GET',
            headers: { authorization: token }
        })
        console.log(res);
        bindHtml(res)
    }
    function bindHtml(res) {
        $('.username').val(res.info.username)
        $('.age').val(res.info.age)
        $('.nickname').val(res.info.nickname)
        $('.gender').val(res.info.gender)
    }
    $('form').on('submit', async e => {
        e.preventDefault()
        console.log($('.gender').val());
        const gender = $('.gender').val()
        const nickname = $('.nickname').val()
        const age = $('.age').val()
        const res = await $.ajax({
            url: 'http://localhost:8080/person/update',
            data: { nickname, age, gender, user_id },
            method: 'post',
            dataType: 'json',
            headers: { authorization: token }
        })
        console.log(res);
        bindHtml(res)
    })
})